package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysDynamicParise;
import com.ruoyi.project.system.service.ISysDynamicPariseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 动态点赞Controller
 *
 * @author jjp
 * @date 2020-07-15
 */
@RestController
@Api(description = "手机动态点赞")
@RequestMapping("/mobileUser/dynamicParise")
public class UserDynamicPariseController extends BaseController {
    @Autowired
    private ISysDynamicPariseService sysDynamicPariseService;


    /**
     * 查询动态点赞列表
     */
    @ApiOperation("查询动态点赞列表")
    @GetMapping("/list")
    public TableDataInfo list(SysDynamicParise sysDynamicParise)
    {
        sysDynamicParise.setMobileUserId(SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId());
        startPage();
        List<SysDynamicParise> list = sysDynamicPariseService.selectSysDynamicPariseList(sysDynamicParise);
        return getDataTable(list);
    }



    /**
     * 新增动态点赞
     */
    @ApiOperation("新增动态点赞")
    @Log(title = "动态点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDynamicParise sysDynamicParise) {
        sysDynamicParise.setMobileUserId(SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId());
        List<SysDynamicParise> list = sysDynamicPariseService.selectSysDynamicPariseList(sysDynamicParise);
        if (0 == list.size()) {
            sysDynamicPariseService.insertSysDynamicParise(sysDynamicParise);
            Integer countParise = sysDynamicPariseService.selectCountParise();
            return AjaxResult.success(countParise);
        }
        return AjaxResult.error("您已点过赞！");
    }


    /**
     * 删除动态点赞
     */
    @ApiOperation("删除动态点赞")
    @Log(title = "动态点赞", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public AjaxResult remove(@RequestBody SysDynamicParise sysDynamicParise) {
        sysDynamicParise.setMobileUserId(SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId());
        int i = sysDynamicPariseService.deleteSysDynamicPariseByDynamic(sysDynamicParise);
        Integer countParise = sysDynamicPariseService.selectCountParise();
        return AjaxResult.success(countParise);
    }
}
